package leetcode.L1000;

import java.util.Deque;
import java.util.LinkedList;

public class EX5631 {
    public static void main(String[] args) {

        int [] line = {1,3,-1,-3,5,3,6,7};
        int k = 3;

        Deque<Integer> deque = new LinkedList<>();
        //单调队列存储的是数组的索引号

        for (int i = 0; i <line.length ; i++) {
            if(!deque.isEmpty()&&deque.peekFirst()<i-k+1){
                deque.pollFirst();
            }
            while(!deque.isEmpty()&&line[deque.peekLast()]>=line[i]){
                deque.pollLast();
            }
            deque.addLast(i);
            System.out.println(line[deque.peekFirst()]);
        }

    }
}
